extern crate fejpsl_contract;
use fejpsl_contract::exam::blank_filling_question::BlankFillingQuestion;

pub async fn get_blank_filling_question_by_id(id:&i32) -> Option<BlankFillingQuestion> {
    let client = super::super::db::connect().await.unwrap();
    let rows = &client.query("SELECT a.id, score, correct, info_text_content_id,b.content
	    FROM public.t_question a left join t_text_content b on a.info_text_content_id=b.id
	    where question_type=4 and a.id=$1", &[&id]).await.unwrap();
    let row = rows.get(0).unwrap();
    let blank_filling_question = BlankFillingQuestion {
        id:   row.get(0),
        score: row.get(1),
        correct:  row.get(2),
        info_text_content_id:   row.get(3),
        content: row.get(4),
    };
    return Some(blank_filling_question);
}

pub async fn list_blank_filling_question(subject_id:&i32) -> Option<Vec<BlankFillingQuestion>> {
    let client =super::super::db::connect().await.unwrap();
    let mut vec_blank_filling_question = Vec::new();
    let rows = &client.query("SELECT a.id, score, correct, info_text_content_id,b.content
	    FROM public.t_question a left join t_text_content b on a.info_text_content_id=b.id
	    where question_type=4 and subject_id=$1;", &[&subject_id]).await.unwrap();
    for row in rows {
        let blank_filling_question = BlankFillingQuestion {
            id:   row.get(0),
            score: row.get(1),
            correct:  row.get(2),
            info_text_content_id:   row.get(3),
            content: row.get(4),
        };
        vec_blank_filling_question.push(blank_filling_question);
    }
    return Some(vec_blank_filling_question);
}
